package com.hnkywl.jip.dao;

import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 说明：
 * 包:        com.hnkywl.jip.dao
 * 类描述:    [一句话描述该类的功能]
 * 创建人:    ZHUCHG
 * 创建时间: 13-3-4 上午8:51
 * 修改人:    ZHUCHG
 * 修改时间: 13-3-4 上午8:51
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Repository
public class BasicDao extends SimpleHibernateTemplate {
    public List findCustomer(String key) {
        String sql = "select top 30 custid,name from t_cw_cust where name+isnull(keyword,'') like ?";
        List<Object[]> result = createSQLQuery(sql, "%" + key + "%").list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }

    public List getVoucherTypeCode(Integer companyId) {
        String sql = "select jlcsignid,name from t_cw_sys_word where compid=?";
        List<Object[]> result = createSQLQuery(sql, companyId).list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }

    public List getAllSubject(Integer companyId) {
        String sql = "select distinct code=clazz,parent_code=null,leaf='',name=clazz,assist_accounting_type='' from t_jiuqi_subject union all " +
                "select code,isnull(parent_code,clazz),leaf,name,assist_accounting_type from t_jiuqi_subject where status=1 and company_id=?";
        List<Object[]> result = createSQLQuery(sql, companyId).list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }

    public List findDept(Integer companyId) {
        String sql = "select d.deptid,name=c.shortname+'-'+d.name,d.u8code from t_sys_dept d,t_cw_cust c where d.compid=c.custid and d.status=1 and d.compid=?";
        List<Object[]> result = createSQLQuery(sql, companyId).list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }

    public List findUser(Integer deptId) {
        String sql = "select u.manid,u.name,e.u8code from t_sys_user u,t_hr_emp e where u.manid=e.manid and u.status=1 and e.u8code is not null and e.deptid=?";
        List<Object[]> result = createSQLQuery(sql, deptId).list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }
}
